#include "comm.hpp"
//#include "log.hpp"
#include <iostream>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
using namespace std;
int main()
{
    //Log log;
    // 创建共享内存
    key_t k = ftok("/home/ly/brilliant-alone/Linuxcode/IPC", 0x6666);
    int shmid = shmget(k,4096, IPC_CREAT|IPC_EXCL|0666);
    if(shmid < 0)
    {
        //cout << "shmget fail" <<  endl;
        cout << strerror(errno) <<  endl;
        return -1;
    }
    //挂到进程地址空间
    char* add = (char*)shmat(shmid, nullptr, 0);
    //读取
    while(1)
    {
        cout << "client say:" << add <<endl;
        sleep(1);
    }

    //断开挂起
    shmdt(add);
    //关闭
    shmctl(shmid, IPC_RMID, nullptr);
    return 0;
}

